/**
 * 
 */
package co.fitstart.tencent.customer.entity.webauth;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;

/**
 * @author downpour
 *
 */
@Entity
@Table(name = "web_auth_client")
public class WebAuthClient {
    
    /** The primary key ( 2 digits ) */
	@Id
	@GenericGenerator(name = "generator", strategy = "assigned")
    @GeneratedValue(generator = "generator")
    private String id;
    
    /** The supporting host */
    private String host;
    
    /** The client auth success callback url */
    private String redirectUrl;
    
    /** The client auth error callback url */
    private String errorUrl;
    
    /**
     * The default constructor
     */
    public WebAuthClient() {
        
    }

    /**
     * 
     * @return
     */
    public boolean isValid() {
        return StringUtils.isNotBlank(this.id) 
            && StringUtils.isNotBlank(this.host) 
            && StringUtils.isNotBlank(this.redirectUrl) 
            && StringUtils.isNotBlank(this.errorUrl);
    }
    
    /**
     * 
     * @return
     */
    public WebAuthConfig toWebAuthConfig() {
        return new WebAuthConfig(this.id, this.generateCallbackUrl(), this.generateErrorBackUrl());
    }

    /**
     * Get success callback url
     * 
     * @return
     */
    public String generateCallbackUrl() {
        return com.demo2do.core.utils.StringUtils.connect(this.host, this.redirectUrl);
    }
    
    /**
     * Get error callback url
     * 
     * @return
     */
    public String generateErrorBackUrl() {
        return com.demo2do.core.utils.StringUtils.connect(this.host, this.errorUrl);
    }

    /**
     * @return the id
     */
    public String getId() {
        return this.id;
    }

    /**
     * @return the host
     */
    public String getHost() {
        return this.host;
    }

    /**
     * @return the redirectUrl
     */
    public String getRedirectUrl() {
        return this.redirectUrl;
    }

    /**
     * @return the errorUrl
     */
    public String getErrorUrl() {
        return this.errorUrl;
    }

    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @param host the host to set
     */
    public void setHost(String host) {
        this.host = host;
    }

    /**
     * @param redirectUrl the redirectUrl to set
     */
    public void setRedirectUrl(String redirectUrl) {
        this.redirectUrl = redirectUrl;
    }

    /**
     * @param errorUrl the errorUrl to set
     */
    public void setErrorUrl(String errorUrl) {
        this.errorUrl = errorUrl;
    }

}
